package cn.bugio.note.sentinel;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.UrlCleaner;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.stereotype.Component;


import java.util.Arrays;

/**
 * @author Vincent Vic
 * @version 1.0
 * @Description
 * @since 2021/2/28
 */

//@Component
@Slf4j
public class MyUrlCleaner implements UrlCleaner {
    @Override
    public String clean(String originUrl) {
        log.info("originUrl = {}",originUrl);
        String[] split = originUrl.split("/");
        Arrays.stream(split)
                .map(string -> {
                    if (NumberUtils.isNumber(string)){
                        return "{number}";
                    }
                    return string;
                })
        .reduce((a,b) -> a +"/" +b)
        .orElse("");

        return originUrl;
    }
}
